package beans.impl;

import beans.Account;
import exception.IllegalAmountException;
import exception.IllegalIdException;
import exception.IllegalNameException;
import exception.InsufficientFundsException;
//import javax.persistence.Entity;
//import javax.persistence.Id;
//import javax.persistence.Table;

/**
 * Compte utilisateur (client/magasin)
 * @author M2 MIAGE Apprentissage - Groupe 3 (JPastor)
 */
public class AccountBean implements java.io.Serializable, Account {

    private String accountId; //Numéro IBAN
    private String accountOwner;
    private double balance;

    public AccountBean() {}

    public AccountBean(String accountId, String accountOwner, double balance) throws IllegalAmountException, IllegalIdException, IllegalNameException {
        //Vérification des conditions
        if(accountId == null) throw new IllegalIdException();
        if(accountOwner == null) throw new IllegalNameException();
        if(balance < 0) throw new IllegalAmountException();

        //Constructeur
        this.accountId = accountId;
        this.accountOwner = accountOwner;
        this.balance = balance;
    }

    public String getAccountId() {
        return accountId;
    }
    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getAccountOwner() {
        return accountOwner;
    }
    public void setAccountOwner(String accountOwner) {
        this.accountOwner = accountOwner;
    }

    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void deposit(double amount) throws IllegalAmountException {
        //Vérification des conditions
        if(amount <= 0) throw new IllegalAmountException();

        //Ajout du montant
        this.balance += amount;
    }

    public double withdraw(double amount) throws IllegalAmountException, InsufficientFundsException {
        //Vérification des conditions
        if(amount <= 0) throw new IllegalAmountException();
        if(this.balance < amount) throw new InsufficientFundsException();

        //Retrait du montant
        this.balance = this.balance - amount;

        return this.balance;
    }

}
